<template>
  <div class="select_number flex">
    <div class="companies">
      <div class="height12"></div>
      <el-input
        class="input"
        placeholder="输入关键字进行过滤"
        v-model="filterText"
      ></el-input>
      <div class="height12"></div>
      <el-tree
        class="filter-tree"
        :data="companyDepartmentData"
        :props="defaultProps"
        default-expand-all
        :filter-node-method="filterNode"
        @node-click="handleSelect"
        ref="tree"
      >
      </el-tree>
    </div>
    <div class="numbers">
        <!-- 搜索框 -->
        <div class="search_number">
            <el-input class="search_input" v-model="Keyword" placeholder="请输入关键字进行过滤"></el-input>
        </div>
        <!-- 已选择人员 -->
        <div class="has_select_number">
            <div class="has_select_number_title">已选人员：</div>
            <div class="has_select_number_items">
                <div class="has_select_number_items_" v-show="hasSelectStaff.length > 0">
                    <div class="has_select_number_items_name" 
                      v-for="(item,index) in hasSelectStaff" :key="index">
                      {{item.F_RealName}}
                    </div>
                    <div class="has_select_number_items_close" @click="delStaff"><img src="../../assets/imgs/closed.png" ></div>
                </div>
            </div>
        </div>
        <!-- 人员列表 -->
        <div class="staff_list">
          <div class="no_select_number_items_name" 
              v-for="(item,index) in staffList" 
              :key="index"
              :title="item.F_RealName"
              @click="selectStaff(item)">
              {{item.F_RealName}}
          </div>
        </div>
    </div>
  </div>
</template>

<!-- 获取部门下的人员，不分页(有权限)/departments/{id}/users -->
<!-- 获取部门下的人员，不分页(无权限)/users/page -->
<!-- Request URL: http://localhost:2828/users/page?Company_Id=21db6a365d2f1254dac92f9ec314deaa&limit=1&size=20 -->
<!-- Request URL: http://localhost:2828/users/page?Company_Id=21db6a365d2f1254dac92f9ec314deaa&limit=1&size=20&Department_Id=10a53c48f98cac823cbfb75477554eee -->


<script>
import { getCompanyDepartments } from "@/api/organization/department";
import { getCompaniesUserList} from "@/api/organization/user";
import { log } from 'video.js';

export default {
  data() {
    return {
        filterText: "",
        companyDepartmentData: [],
        defaultProps: {
            children: "children",
            label: "F_FullName",
        },
        currentPage:1,//当前页数
        pageSize:20,//每页大小
        Keyword:'',//关键词
        departmentId:'',//部门id
        staffList:'',//员工列表
        hasSelectStaff:[],//已选人员
    };
  },
  watch: {
    filterText(val) {
      console.log("val:-", val);
      this.$refs.tree.filter(val);
    },
  },
  async mounted() {
    await this.getTree()
  },
  methods: {
    init(){
      this.hasSelectStaff = []
    },
    getTree(){
        getCompanyDepartments().then(res => {
            if(res.data.success){
                this.companyDepartmentData = res.data.data
            }
        })
    },
    //过滤
    filterNode(value, data) {
      if (!value) return true;
      return data.F_FullName.indexOf(value) !== -1;
    },
    handleSelect(data) {
        let params = {
            Company_Id: data.F_CompanyId,//公司id
            limit: this.currentPage,//当前页
            size: this.pageSize,//每页显示大小
            Keyword: this.Keyword,//关键字
            Department_Id: data.F_DepartmentId,//部门id
        };
        getCompaniesUserList(params).then(res => {
          if(res.data.success){
            this.staffList = res.data.data.Rows
          }
        })
    },
    selectStaff(item){
      this.hasSelectStaff = []
      this.hasSelectStaff.push(item)
      this.$emit("staff",item)
    },
    delStaff(){
      this.hasSelectStaff = []
    }
  },
};
</script>
<style scoped>
.border {
  border: 1px solid red;
}
.select_number {
  width: 100%;
  height: 500px !important;
}
.flex {
  display: flex;
  flex-direction: row;
}
.companies,
.numbers {
  height: 100%;
}
.companies {
  width: 20%;
  border: 1px solid #eee;
  overflow: scroll;
}
.numbers {
  width: 80%;
  height: 100%;
  border: 1px solid #eee;
}
.search {
  width: 100%;
  height: 52px;
  border: 1px solid red;
}
.height12 {
  height: 12px;
}
.input {
  width: 90%;
  margin-left: 12px;
}
.search_number{
    width: 100%;
    height: 40px;
    border-bottom: 1px solid #eee;
    text-align: left;
}
.has_select_number{
    width: 100%;
    height: 40px;
    border-bottom: 1px solid #eee;
    display: flex;
    flex-direction: row;
}
.has_select_number_title{
    width: 100px;
    height: 40px;
    line-height: 40px;
    font-size: 16px;
    text-indent: 16px;
    color: #333;
}
.has_select_number_items{
    height: 40px;
}
.has_select_number_items_{
    width: 80px;
    height: 32px;
    border-radius: 8px;
    margin-top: 4px;
    background: #F2F6FC;
    text-align: center;
    display: flex;
    flex-direction: row;
    overflow: hidden;

}
.has_select_number_items_name{
    width: 70px;
    height: 100%;
    line-height: 32px;
}
.no_select_number_items_name{
    width: 70px;
    height: 32px;
    line-height: 32px;
    background: #F2F6FC;
    text-align: center;
    border: 1px solid #0063f5;
    border-radius: 4px;
    margin-top: 12px;
    float: left;
    margin-left:36px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.no_select_number_items_name:hover{
    width: 70px;
    height: 32px;
    line-height: 32px;
    background: #0063f5;
    text-align: center;
    border: 1px solid #0063f5;
    border-radius: 4px;
    color: #fff;
    cursor: pointer;
}
.has_select_number_items_close{
    width: 30px;
    height: 100%;
    position: relative;
    text-align: left;
}
.has_select_number_items_close:hover{
  cursor: pointer;
}
.has_select_number_items_close::after{
  content: '';
  display: inline-block;
  height: 100%;
  width: 1px;
  vertical-align: middle;
}
.has_select_number_items_close > img{
  vertical-align: middle;
}
.has_select_number_items_::after{
    content: '';
    display: inline-block;
    height: 100%;
    width: 1px;
    vertical-align: middle;
}
.has_select_number_items_ > img{
    vertical-align: middle;
}
.search_button{
    margin-left: 16px;
}
.reset_button{

    margin-right: 16px;
}
.search_input{
    width: 250px;
    margin-top: 4px;
    margin-left: 16px;
}
.staff_list{
  height: 400px;
  overflow:scroll;
}

</style>
